package org.dandelion.memo.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

public abstract class BaseActivity extends AppCompatActivity {
    private static final String TAG = "BaseActivity";
    private Toast toast = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d(TAG, getClass().getSimpleName());
        ActivityCollector.add(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ActivityCollector.remove(this);
    }

    private void showToast(CharSequence text, int duration) {
        if (toast != null) {
            toast.cancel();
        }

        toast = Toast.makeText(getBaseContext(), text, duration);
        toast.show();
    }

    protected void showToast(CharSequence text) {
        showToast(text, Toast.LENGTH_SHORT);
    }

    protected void showLongToast(CharSequence text) {
        showToast(text, Toast.LENGTH_LONG);
    }
}